package com.jc.oms.controller.task.supplierlogistics;

import com.jc.ds.model.LogisticsCompany;
import com.jc.ds.model.Supplier;
import com.jc.ds.model.SupplierLogisticsCompany;
import com.jc.service.logisticscompany.LogisticsCompanyService;
import com.jc.service.supplier.SupplierService;
import com.jc.service.supplierlogisticscompany.SupplierLogisticsCompanyService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
@RequestMapping("supplierLogisticsTask")
public class SupplierLogisticsTask {

    @Autowired
    private SupplierService supplierService;
    @Autowired
    private LogisticsCompanyService logisticsCompanyService;
    @Autowired
    private SupplierLogisticsCompanyService supplierLogisticsCompanyService;


    @RequestMapping(value = "/synSupplierLogisticsCompany" , method = RequestMethod.POST)
    public void synSupplierLogisticsCompany(){
        List<Supplier> suppliers = supplierService.queryAll(new Supplier());
        List<LogisticsCompany> logisticsCompanies = logisticsCompanyService.queryAll(new LogisticsCompany());
        for (Supplier supplier:suppliers) {
            for (LogisticsCompany logisticsCompany:logisticsCompanies) {
                //查询当前供应商是否存在当前快递
                SupplierLogisticsCompany supplierLogisticsCompany = new SupplierLogisticsCompany();
                supplierLogisticsCompany.setShopLogisticsName(logisticsCompany.getName());
                supplierLogisticsCompany.setShopChannel("3000");
                supplierLogisticsCompany.setSupplierName(supplier.getFullName());
                supplierLogisticsCompany.setSupplierLogisticsName(logisticsCompany.getName());
                List<SupplierLogisticsCompany> supplierLogisticsCompanies = supplierLogisticsCompanyService.queryAll(supplierLogisticsCompany);
                if (supplierLogisticsCompanies == null || supplierLogisticsCompanies.size() < 1){
                    //不为空保存
                    supplierLogisticsCompany.setShopLogisticsCode(logisticsCompany.getChannelLogisticsId());
                    supplierLogisticsCompany.setSupplierSn(supplier.getSupplierSn());
                    supplierLogisticsCompanyService.add(supplierLogisticsCompany,false);
                }
            }
        }


    }


}
